{extend name="public/base" /}
{block name="body"}
<div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-header">数据库管理</div>
            <div class="layui-card-body">
                <div class="layui-tab">
                    <ul class="layui-tab-title">
                        <li><a href="{:url('?type=export')}">备份数据库</a></li>
                        <li class="layui-this">还原数据库</li>
                    </ul>
                    <div class="layui-tab-content layui-row">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form">
                                <table class="layui-table">
                                    <thead>
                                    <tr>
                                        <th width="200">备份名称</th>
                                        <th width="80">卷数</th>
                                        <th width="80">压缩</th>
                                        <th width="80">数据大小</th>
                                        <th width="200">备份时间</th>
                                        <th>状态</th>
                                        <th width="120">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {volist name="list" id="data"}
                                    <tr>
                                        <td>{:date('Y-m-d H:i:s',$data['time'])}</td>
                                        <td>{$data.part}</td>
                                        <td>{$data.compress}</td>
                                        <td>{$data.size|format_bytes}</td>
                                        <td>{$key}</td>
                                        <td>-</td>
                                        <td class="action">
                                            <a class="db-import" href="{:url('import?time='.$data['time'])}">还原</a>&nbsp;
                                            <a class="ajax-post confirm" href="{:url('del?time='.$data['time'])}">删除</a>
                                        </td>
                                    </tr>
                                    {/volist}
                                    </tbody>
                                </table>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script>
    var loadIndex;
    layui.use(['jquery'], function(){
        var $=layui.$;

        $(".db-import").click(function(){

            var self = this, status = ".";
            $.get(self.href, success, "json");
            window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
            return false;

            function success(data){
                if(data.code){
                    if(data.gz){
                        data.msg += status;
                        if(status.length === 5){
                            status = ".";
                        } else {
                            status += ".";
                        }
                    }
                    $(self).parent().prev().text(data.msg);
                    if(data.data.part){
                        $.get(self.href,
                            {"part" : data.data.part, "start" : data.data.start},
                            success,
                            "json"
                        );
                    }  else {
                        window.onbeforeunload = function(){ return null; }
                    }
                } else {
                    top.layer.msg(data.msg?data.msg:'操作失败',{icon: 2,time:data.wait*1000});
                }
            }
        });

    });
</script>
{/block}
